package com.ruoyi.web.app.user;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.base.user.dto.UserLoginDTO;
import com.ruoyi.common.base.user.dto.UserRegisterDTO;
import com.ruoyi.common.base.user.vo.UserLoginRes;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户Controller
 *
 * @author gdk
 * @date 2023-05-15
 */
@RestController
@AllArgsConstructor
@RequestMapping("/app/user")
public class UserAppController extends BaseController {
    private final IUserService userService;

    /**
     * snsapi_userinfo注册
     *
     * @param dto dto
     * @return {@link AjaxResult}
     * @author gdk
     * @since 2023/5/22 19:37
     */
    @Anonymous
    @PostMapping("/registry/wechat/code")
    public AjaxResult registryWechatCode(@Validated @RequestBody UserRegisterDTO dto) {
        UserLoginRes res = userService.registryWechatCode(dto.getCode());
        return success(res);
    }


    /**
     * snsapi_base尝试登录
     *
     * @param dto dto
     * @return {@link AjaxResult}
     * @author gdk
     * @since 2023/5/22 19:37
     */
    @Anonymous
    @PostMapping("/login/wechat/code")
    public AjaxResult loginWechatCode(@Validated @RequestBody UserLoginDTO dto) {
        UserLoginRes res = userService.loginWechatCode(dto.getCode());
        return success(res);
    }

    /**
     * 定时空请求，刷新登录态
     *
     * @return {@link AjaxResult}
     * @author gdk
     * @since 2023/5/26 16:45
     */
    @GetMapping("/refresh/token")
    public AjaxResult refreshToken() {
        return success();
    }
}
